package cn.zhujs.org.service.impl;

import cn.zhujs.basic.util.PageList;
import cn.zhujs.org.domain.Department;
import cn.zhujs.org.mapper.DepartmentMapper;
import cn.zhujs.org.query.DepartmentQuery;
import cn.zhujs.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service //交给容器管理
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS) //添加事务
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    DepartmentMapper departmentMapper;
    @Override
    public void add(Department department) {
         departmentMapper.save(department);
    }

    @Override
    public void remove(Long id) {
         departmentMapper.delete(id);
    }

    @Override
    public void update(Department department) {
         departmentMapper.update(department);
    }

    @Override
    public Department queryById(Long id) {
        //查询有返回值
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> queryAll() {
        //查询有返回值
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery departmentQuery) {
        //1、查询总条数
        Long total=departmentMapper.queryCount(departmentQuery);
        //2、查询当前页的数据
        List<Department> rows=departmentMapper.queryData(departmentQuery);
        return new PageList<>(total,rows);
    }
}
